<?php
/*

Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/
include_once($semf_root.'page_designer/components/Component.php');

class PageComponent extends Component
{
	public static function get_properties()
	{
		return array('Apearance'=> array(
							'Title'=> 'Page',
							'Width'=> '1000',
					 		'Height'=> '800'),
					 'Action Handlers'=> array(
							'onLoad'=> '')
					 );	
	}
		
	
	/** build properties dynamically if atmost one property is changed*/
	public static function build_properties($parent_container, $properties, $property_group, $key, $value)
	{
		//echo $property_group."..";
		//print_r($properties);
		if( $key != NULL )
		{
			$properties[$property_group][$key] = $value;
		}
		return 	$properties;
	}
	
	public static function build_containers( $parent_container, $properties)
	{
		$component = $parent_container->firstChild;
		
		$apearance_properties = $properties['Apearance'];
		
		$width = $apearance_properties['Width'];
		$height = $apearance_properties['Height'];
				
		
		$component_id = $component-> getAttribute('id');
		
		$container_id = "_".$component_id;
		
		$x = $y = 0;
		
		//print_r($properties);
		
		//we do have one container...
		return array( $container_id => 
								array (	'x' => $x,
										'y' => $y,
										'width' => $width,
										'height' => $height
										)
					);
	}

	public static function get_action_info($component_id)
	{
		return array('onLoad'=> array(
							'action' => action::$LOAD,
							'elem1' => "page_".$component_id,));
	}

	public static function load_html_properties($properties, $html_properties)
	{
		$title = $properties['Apearance']['Title'];
		//print_r($properties);
		if( $title == NULL || $title == "")
		{
			$title = "Page xxx";
		}
		$html_properties['title'] = $title;
		
		//print_r($html_properties);
		return $html_properties;
	}
	
	public static function save_html_properties($properties, $html_properties)
	{
		$page_xml = $html_properties["page_xml"];
		$page_xml = basename($page_xml);
		$pos = strpos($page_xml, ".xml");
		$page_name = substr($page_xml, 0, $pos);
		
		$properties['Apearance']['Title'] = $page_name;
		return $properties;
	}
}
?>